<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>新增试题</title>
	<script charset="utf-8" src='<c:url value="/js/jquery.min.js"></c:url>'></script>
	<script charset="utf-8" src='<c:url value="/pages/kindeditor/kindeditor.js"></c:url>'></script>
	<script charset="utf-8" src='<c:url value="/pages/kindeditor/lang/zh_CN.js"></c:url>'></script>
	<script type="text/javascript" src='<c:url value="/js/boot.js"></c:url>'></script>
	<script type="text/javascript"
		src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
	<style>
		html,body{
			margin: 0;
			padding: 0;
			font-family: "微软雅黑";
		}
		li{
			list-style: none;
		}
		a{
			text-decoration: none;
		}
		.Basic_course_content{
			width: 1920px;
			width: 100%;
		}
		.Basic_course_content_content{
			width: 1280px;
			margin: 0 auto;
		}
		.Basic_course_content_content_content{
			width: 780px;
 		    margin-left: 104px;
    		margin-top: 24px;
			text-align: left;
		}
		.Basic_course_content_content_content_title{
			color: #2459aa;
			font-size: 18px;
			padding-bottom: 5px;
			border-bottom: 2px solid #2459aa;
			/*font-weight: 600;*/
		}
		.Basic_course_content_content_content_content{
			/*padding: 25px 0;   */
			/* 25 0*/
		}
		.Basic_course_content_content_content_content>ul>li{
			padding: 16px 0;
		}
		.Basic_course_content_content_content_content>ul{
			margin: 0;
			padding: 0;
			margin-bottom: 16px;
		}
		.Basic_course_content_content_content_content>ul>li>div>span{
			float: left;
			font-size: 16px;
			padding: 4px 0;
		}
		.Basic_course_content_content_content_content>ul>li>div>span>font{
			color: #ff0000;
		}
		.Basic_course_content_content_content_content>ul>li>div input[type="text"]{
			/*width: 423px;*/
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select{
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>textarea{
			width: 420px;
			padding: 5px;
    		margin-top: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select>option{
			padding: 3px;
		}
		.Basic_course_baocun{
			background: #2459aa;
			color: #fff;
			font-size: 16px;
			padding: 5px 15px;
			border-radius: 3px;
			margin-left: 92px;
		}
		/**/
		.New_course_type ul{
			margin:0;
			padding:0;
		}
		.New_course_type li{
			display: inline-block;
		    padding: 4px 14px 6px 14px;
 		    /*border: 1px solid;*/
 		    color: #2459aa;
 		    cursor: pointer;
		}
		.New_course_type li:hover{
			background: #2459aa;
			color: white;
			border-radius: 0px 0px 6px 6px;
		}
		.current_page{
			background: #2459aa;
			color: white !important;
			border-radius: 0px 0px 6px 6px;
		}
		.leftmargin{
			margin-left: 93px;
			/*border:1px solid black;*/
		}
		.bottommargin{
			margin-bottom: 13px;
			width: 401px !important;
		}
		#one_choice_form1,#one_choice_form2{
			width:432px;
		}
		.fixedWidth{
			width: 22px; /* 432-401-5*2*/
		}
		.inlineDisplay{
			display: inline-block;	
		}


		/**/
		
		
		/*  */
		.mini-buttonedit-border {
    		height: 29px;
    	}
	    .mini-buttonedit-icon {
	    	margin-top:6px !important;
		}
		.mini-buttonedit-button {
		    height: 29px !important;
		}
    	.mini-buttonedit-border, .mini-textbox-border {
    		border-radius: 0px !important;
    	}
    	.mini-buttonedit-input {

		    height: 29px !important;
		}


		/*  */
		#dialog{
			background-color:#fff;
			width:800px;
			/*height: 800px;*/
			position:absolute;
			top:12%;
			left: calc(50% - 400px);
			z-index:11;
			box-shadow: 0 1px 2px grey;
			display: none;

			}
			#abc{
			position: absolute;
			top:20%;
			left: 360px;
			z-index: 2;
			} 
					
			.maskLayer{  
			z-index:10;
			opacity:0.3; 
			filter: alpha(opacity=30); 
			background-color:#ccc;
			}
			.questions_stems{
				border: 1px solid #a4a4a4;
				padding: 6px 12px;
				margin:0px 30px;
				font-size: 13px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.options{
				border: 1px solid #a4a4a4;
				padding: 10px 25px;
				margin: 5px 30px;
				font-size: 13px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.options>li{
				padding: 2px 15px;
				font-size: 13px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.answer{
				border: 1px solid #a4a4a4;
				padding: 10px;
				margin: 5px 30px;
				font-size: 13px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.answer_detail{
				border: 1px solid #a4a4a4;
				padding: 10px;
				margin: 5px 30px 30px 30px;
				font-size: 13px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.answer_detail>p{
				margin-left: 80px;
				max-height: 400px;
				overflow-y: auto;
			}
		.haha{
			/* width:100%; */
			/* height:100%; */
			z-index:10;/*注意此数值不得大于登陆框的z-index数值*/
			background-color:rgba(0,0,0,0.5);
			position:absolute;
			left:0px;
			top:0px;
			display:none;
		}
	</style>
</head>
<body>
	<div class="Basic_course_content">
		<div class="Basic_course_content_content">
			<div class="Basic_course_content_content_content">
				<div class="Basic_course_content_content_content_title">
					新建试题
				</div>

				<div class="New_course_type">
					<ul>
						<li id="one_choice_type" class="current_page">单选题</li>
						<li id="multiple_choice_type">多选题</li>
						<li id="true_or_false_type">判断题</li>
						<li id="solution_type">解答题</li>
					</ul>
				</div>
				<!-- 题干 -->
				<div class="Basic_course_content_content_content_content">
					<ul>
						<li>
							<div>
								<span><font>*</font> 题干：</span>
								<input type="text" id = "stem" style="margin-left:33px;width:423px;">
							</div>
						</li>
					</ul>
				</div>

				<!-- 单选题页面 -->
				<div class="Basic_course_content_content_content_content" id="one_choice_content">
					<ul>
						
						<li>
							<div>
								<span><font>*</font> 选项：</span>
								<div class="leftmargin">
									<form id="one_choice_form1">
										<div>
										    <span class="fixedWidth inlineDisplay">A</span><input id = "A" name = "A"type="text" class="bottommargin">
										</div>
										<div>
										    <span class="fixedWidth inlineDisplay">B</span><input id = "B" name = "B" type="text" class="bottommargin">
										</div>
										<div>
										    <span class="fixedWidth inlineDisplay">C</span><input id = "C" name = "C" type="text" class="bottommargin">
										</div>
										<div>
										    <span class="fixedWidth inlineDisplay">D</span><input id = "D" name = "D" type="text" class="bottommargin">
										</div> 
								    </form>
								    <a style="font-size:13px;cursor:pointer;" id="one_choice_add_options1">+ 增加选项</a>&nbsp;&nbsp;&nbsp;
								    <a style="font-size:13px;cursor:pointer;" id="one_choice_del_options1">- 减少选项</a>
							    </div>
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 正确答案：</span>
								<div class="leftmargin" style="text-align:left;">
									<form action="" id="one_choice_form2">
										<div class="inlineDisplay">
											<input type="radio" style="" name="one_choice_answer" value = "A"><span class="fixedWidth ">A</span>
										</div>
										<div class="inlineDisplay">
											<input type="radio" style="" name="one_choice_answer" value = "B"><span class="fixedWidth">B</span>
										</div>
										<div class="inlineDisplay">
											<input type="radio" style="" name="one_choice_answer" value = "C"><span class="fixedWidth">C</span>
										</div>
										<div class="inlineDisplay">
											<input type="radio" style="" name="one_choice_answer" value = "D"><span class="fixedWidth">D</span>
										</div>
									</form>
								</div>
							</div>
						</li>
					</ul>
				</div>
				


				<!-- 多选题页面 -->
				<div class="Basic_course_content_content_content_content" id="multiple_choice_content" style="display:none;">
					<ul>
						<li>
							<div>
								<span><font>*</font> 选项：</span>
								<div class="leftmargin">
									<form id="multiple_choice_form1"> 
									    <div>
										    <span class="fixedWidth inlineDisplay">A</span><input type="text" class="bottommargin">
										</div>
										<div>
										    <span class="fixedWidth inlineDisplay">B</span><input type="text" class="bottommargin">
										</div>
										<div>
										    <span class="fixedWidth inlineDisplay">C</span><input type="text" class="bottommargin">
										</div>
										<div>
										    <span class="fixedWidth inlineDisplay">D</span><input type="text" class="bottommargin">
										</div> 
								    </form>
								    <a id="multiple_choice_add_options1" style="font-size:13px;cursor:pointer;">+ 增加选项</a>&nbsp;&nbsp;&nbsp;
								    <a style="font-size:13px;cursor:pointer;" id="multiple_choice_del_options1">- 减少选项</a>
							    </div>
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 正确答案：</span>
								<div class="leftmargin" style="text-align:left;">
									<form action=""  id="multiple_choice_form2">
										<div class="inlineDisplay">
											<input type="checkbox" style="" name="multiple_choice_answer" value = "A"><span class="fixedWidth ">A</span>
										</div>
										<div class="inlineDisplay">
											<input type="checkbox" style="" name="multiple_choice_answer" value = "B"><span class="fixedWidth">B</span>
										</div>
										<div class="inlineDisplay">
											<input type="checkbox" style="" name="multiple_choice_answer" value = "C"><span class="fixedWidth">C</span>
										</div>
										<div class="inlineDisplay">
											<input type="checkbox" style="" name="multiple_choice_answer" value = "D"><span class="fixedWidth">D</span>
										</div>
									</form>
								</div>
							</div>
						</li>
					</ul>

				</div>


				<!-- 判断题页面 -->
				<div class="Basic_course_content_content_content_content" id="true_or_false_content" style="display:none;">
					<ul>
						<li>
							<div>
								<span><font>*</font> 选项：</span>
								<div class="leftmargin">
									<p>是</p>
									<p>否</p>
							    </div>
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 正确答案：</span>
								<div class="leftmargin" style="text-align:left;">
									<form id = "judge_answer">
										<input type="radio" style="" name="true_or_false_answer" value = "true"><label for="">是</label>&nbsp;&nbsp;&nbsp;&nbsp;
										<input type="radio" style="" name="true_or_false_answer" value = "false"><label for="">否</label>&nbsp;&nbsp;&nbsp;&nbsp;
									</form>
								</div>
							</div>
						</li>
					</ul>
				</div>


				<!-- 解答题页面 -->
				<div class="Basic_course_content_content_content_content" id="solution_content" style="display:none;">
					<ul>
						<li>
							<div>
								<span><font>*</font> 正确答案：</span>
								<textarea id = "solution_answer" rows="8" cols="50"></textarea>
							</div>
						</li>
					</ul>
				</div>

				<!-- 试题详解和所属课程 -->
				<div class="Basic_course_content_content_content_content">
					<ul>
						<li>
							<div class="Basic_course_modify">
								<span><font>*</font> 试题详解：</span>
								<textarea name = "textEditor" runat="server" rows="8" cols="50" placeholder="请填写试题简介" id="editor"></textarea>
							</div>
						</li>
						<li>
							<div>
								<span><font>&nbsp;</font> 所属课程：</span> 
							</div> <input id="lookup2" name="look" class="mini-lookup"
							style="width: 432px;height:32px;" textField="class_name" valueField="id"
							popupWidth="auto" popup="#gridPanel" grid="#datagrid1"
							multiSelect="true" value=""
							text="" />

							<div id="gridPanel" class="mini-panel" title="header"
								iconCls="icon-add" style="width: 450px; height: 250px;"
								showToolbar="true" showCloseButton="true" showHeader="false"
								bodyStyle="padding:0" borderStyle="border:0">
								<div property="toolbar"
									style="padding: 5px; padding-left: 8px; text-align: center;">
									<div style="float: left; padding-bottom: 2px;">
										<span>课程：</span> <input id="keyText" class="mini-textbox"
											style="width: 160px;" onenter="onSearchClick" /> <a
											class="mini-button" onclick="onSearchClick">查询</a> <a
											class="mini-button" onclick="onClearClick">清除</a>
									</div>
									<div style="float: right; padding-bottom: 2px;">
										<a class="mini-button" onclick="onCloseClick">确定</a>
									</div>
									<div style="clear: both;"></div>
								</div>
								<div id="datagrid1" class="mini-datagrid"
									style="width: 100%; height: 100%;" borderStyle="border:0"
									showPageSize="false" showPageIndex="false"
									url='' >
									<div property="columns">
										<div type="checkcolumn"></div>
										<div field="class_name" width="120" headerAlign="center"
											allowSort="true">课程</div>
										<div field="creater" width="120" headerAlign="center"
											allowSort="true">编制人</div>
										<div field="createTime" width="100" headerAlign="center"
											dateFormat="yyyy-MM-dd" allowSort="true">创建日期</div>
									</div>
								</div>
							</div>
						</li>
					</ul>
					<a id = "save" class="Basic_course_baocun" style="cursor:pointer;">保存</a>
					<a id = "preview" class="Basic_course_baocun" style="cursor:pointer;">预览</a>
				</div>


			</div>
		</div>
	</div>
	<div class = "haha" ></div>
	<div id="dialog" style="display:none;">
			<div class="close">
				<img src="<c:url value="/share/img/icon/close_02.png"></c:url>"  onclick="closeBg()" alt="关闭" style="margin-right: -40px;"/>
			</div>
			<div class="questions_stems">
				<font id = "question_stem"></font>
			</div>
			<ul class="options" id = "select_options">
			</ul>
			<div class="answer">
				<span>正确答案:&nbsp;<font id = "preview_answer" style="color: #fa2121;"></font></span>
			</div>
			<div class="answer_detail ">
				<div style="float: left;height: 100px;">
					<span >试题详解: </span>
				</div>
				<p id = "explain_in_detail">
				</p>
			</div>
		</div>
</body>
<script type = "text/javascript">
	var question_type = "单选题";
	///单选题状态
	function state1(){
		question_type = "单选题";
		$("#one_choice_content").show();
		$("#multiple_choice_content").hide();
		$("#true_or_false_content").hide();
		$("#solution_content").hide();
		$("#one_choice_type").addClass("current_page");
		$("#multiple_choice_type").removeClass("current_page");
		$("#true_or_false_type").removeClass("current_page");
		$("#solution_type").removeClass("current_page");
	}
	///多选题状态
	function state2(){
		question_type = "多选题";
		$("#one_choice_content").hide();
		$("#multiple_choice_content").show();
		$("#true_or_false_content").hide();
		$("#solution_content").hide();
		$("#multiple_choice_type").addClass("current_page");
		$("#one_choice_type").removeClass("current_page");
		$("#true_or_false_type").removeClass("current_page");
		$("#solution_type").removeClass("current_page");
	}
	//判断题状态
	function state3(){
		question_type = "判断题";
		$("#one_choice_content").hide();
		$("#multiple_choice_content").hide();
		$("#true_or_false_content").show();
		$("#solution_content").hide();
		$("#true_or_false_type").addClass("current_page");
		$("#one_choice_type").removeClass("current_page");
		$("#multiple_choice_type").removeClass("current_page");
		$("#solution_type").removeClass("current_page");
	}
	//解答题状态
	function state4(){
		question_type = "解答题";
		$("#one_choice_content").hide();
		$("#multiple_choice_content").hide();
		$("#true_or_false_content").hide();
		$("#solution_content").show();
		$("#solution_type").addClass("current_page");
		$("#one_choice_type").removeClass("current_page");
		$("#true_or_false_type").removeClass("current_page");
		$("#multiple_choice_type").removeClass("current_page");
	}
	// 页面切换
	$("#one_choice_type").click(function(){
		if(getFormValue("multiple_choice_form1")||$("#solution_answer").val()
				||getCheckedValues()||
				$("input[name='true_or_false_answer']:checked").val()){
			mini.confirm("未保存,是否继续操作？", "确定？",
		            function (action) {
		                if (action == "ok") {
		                	setFormEmpty("multiple_choice_form1");
		                	$("#solution_answer").val("");
		                	setAnswerEmpty();
		                	state1();
		                } else {
		                	return;
		                }
		           });
		}else{
			state1();
		}
	});
	$("#multiple_choice_type").click(function(){
		if(getFormValue("one_choice_form1")||$("#solution_answer").val()
				||$("input[name='one_choice_answer']:checked").val()||
				$("input[name='true_or_false_answer']:checked").val()){
			mini.confirm("未保存,是否继续操作？", "确定？",
		            function (action) {
		                if (action == "ok") {
		                	setFormEmpty("one_choice_form1");
		                	setAnswerEmpty();
		                	$("#solution_answer").val("");
		                	state2();
		                } else {
		                	return;
		                }
		           });
		}else{
			state2();
		}
		
	});
	$("#true_or_false_type").click(function(){
		if(getFormValue("one_choice_form1")||getFormValue("multiple_choice_form1")
				||$("#solution_answer").val()||getCheckedValues()
				||$("input[name='one_choice_answer']:checked").val()){
			mini.confirm("未保存,是否继续操作？", "确定？",
		            function (action) {
		                if (action == "ok") {
		                	setFormEmpty("multiple_choice_form1");
		                	setFormEmpty("one_choice_form1");
		                	setAnswerEmpty();
		                	$("#solution_answer").val("");
		                	state3();
		                } else {
		                	return;
		                }
		           });
		}else{
			state3();
		}
	});
	$("#solution_type").click(function(){
		if(getFormValue("one_choice_form1")||getFormValue("multiple_choice_form1")
				||getCheckedValues()||$("input[name='true_or_false_answer']:checked").val()||
				$("input[name='one_choice_answer']:checked").val()){
			mini.confirm("未保存,是否继续操作？", "确定？",
		            function (action) {
		                if (action == "ok") {
		                	setFormEmpty("multiple_choice_form1");
		                	setFormEmpty("one_choice_form1");
		                	setAnswerEmpty();
		                	state4();
		                } else {
		                	return;
		                }
		           });
		}else{
			state4();
		}
	});
	
	
	// 增加选项 -- 单选选项
	$("#one_choice_add_options1").click(function(){
		add_one("");
	});
	//增加选项-- 单选
	function add_one(value){
		var oTest = document.getElementById("one_choice_form1");
		var newNode = document.createElement("div");
		var newNode2 = document.createElement("span");
		var newNode3 = document.createElement("input");
		oTest.appendChild(newNode);
		newNode.appendChild(newNode2);
		newNode.appendChild(newNode3);

		newNode2.innerHTML = options_name("one_choice_form1");
		newNode2.style.display = "inline-block";
		newNode2.style.width = "22px";
		newNode3.style.width = "406px";
		newNode3.style.padding = "5px 0px";
		newNode3.style.marginBottom = "13px";
		newNode3.value = value;
		newNode3.id = options_name("one_choice_form1");
		addOneChoice();
	}
	// 增加选项 -- 多选选项
	$("#multiple_choice_add_options1").click(function(){
		add_many("");
	});
	function add_many(value){
		var oTest = document.getElementById("multiple_choice_form1");
		var newNode = document.createElement("div");
		var newNode2 = document.createElement("span");
		var newNode3 = document.createElement("input");
		oTest.appendChild(newNode);
		newNode.appendChild(newNode2);
		newNode.appendChild(newNode3);

		newNode2.innerHTML = options_name("multiple_choice_form1");
		newNode2.style.display = "inline-block";
		newNode2.style.width = "22px";
		newNode3.style.width = "406px";
		newNode3.style.padding = "5px 0px";
		newNode3.style.marginBottom = "13px";

		newNode3.value = value;
		newNode3.id = "M"+options_name("multiple_choice_form1");
		add_many_answer();
	}
	
	function options_name(a) {
		var hei = document.getElementById(a);
		var v1=$(hei).children().length - 1;
		var v2=String.fromCharCode(v1 + 65);
		return v2;
	}
	//增加选项 -- 单选答案
	function addOneChoice(){
		var oTest = document.getElementById("one_choice_form2");
		var newNode = document.createElement("div");
		var newNode2 = document.createElement("span");
		var newNode3 = document.createElement("input");
		oTest.appendChild(newNode);
		newNode.appendChild(newNode3);
		newNode.appendChild(newNode2);
		newNode.style.display = "inline-block";
		newNode2.innerHTML = options_name("one_choice_form2");
		newNode2.style.width = "22px";
		newNode3.type = "radio";
		newNode3.name = "one_choice_answer";

		newNode3.value = options_name("one_choice_form2");
		newNode3.id = options_name("one_choice_form2");

	} 
	
	// 增加选项 -- 多选答案
	function add_many_answer(){
		var oTest = document.getElementById("multiple_choice_form2");
		var newNode = document.createElement("div");
		var newNode2 = document.createElement("span");
		var newNode3 = document.createElement("input");
		oTest.appendChild(newNode);
		newNode.appendChild(newNode3);
		newNode.appendChild(newNode2);
		newNode.style.display = "inline-block";
		newNode2.innerHTML = options_name("multiple_choice_form2");
		newNode2.style.width = "22px";
		newNode3.type = "checkbox";
		newNode3.name = "multiple_choice_answer";
		newNode3.value = options_name("multiple_choice_form2");
	}
	function deleteOptions(a) {
		var v1=document.getElementById(a);
		v1.removeChild(v1.lastChild);
	}
	//减少选项
	$("#one_choice_del_options1").click(function(){
		deleteOptions("one_choice_form1");
		deleteOptions("one_choice_form2");
	});
	$("#multiple_choice_del_options1").click(function(){
		deleteOptions("multiple_choice_form1");
		deleteOptions("multiple_choice_form2");
	});
	
	<!-- ////////////////////////////////////////////////////////--->
	mini.parse();
	mini_debugger = false;
	var datagrid1 = mini.get("datagrid1");
	var rootPath = '${rootPath}';
	var keyText = mini.get("keyText");
	var filterHelper = gridFilter();
	 var lookup2 = mini.get("lookup2");
	
	$(function() {
		loadGrid1();
	})
	// miniui lookup
	function onSearchClick(e) {
		var key = keyText.getValue();
		filterHelper.clearFilterData();
		if (key != "") {
			var filterdata = filterHelper.formFilterData("class_name",
					key, '', 'CONTAIN', 'AND');
			filterHelper.addFilterData(filterdata);
		}
		
		loadGrid1();
    }
	function loadGrid1() {
		var filterData = filterHelper.getFilterData();
		var postData = new Object();
		if (filterData != null || filterData.length > 0) {
			postData.filterdata = mini.encode(filterData);
		}
		var url = "<c:url value='/question/courseList' />";
		datagrid1.load(url);
		datagrid1.load(postData);
	}
    function onCloseClick(e) {
        lookup2.hidePopup();
    }
    function onClearClick(e) {
        lookup2.deselectAll();
        keyText.setValue();
        filterHelper.clearFilterData();
        loadGrid1();
    }
    ////////////////////////保存\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	function save(string) {
		var course_name = lookup2.getText();//所属课程
		var question = $("#stem").val();//题干
		if(question == ""){
			mini.alert("请填写题干");
			return;
		}
		var detailed = string;//详解
		var answer;
		var selects;
		if(question_type == "单选题"){
			selects = getFormValue("one_choice_form1");//题目选项
			answer = $("input[name='one_choice_answer']:checked").val();
			if(!selects){
				top.commonTools.showTip("请填写选项!", 2);
				return;
			}
			
		}else if(question_type == "多选题"){
			selects = getFormValue("multiple_choice_form1");//题目选项
			answer = getCheckedValues();
			if(!selects){
				top.commonTools.showTip("请填写选项!", 2);
				return;
			}
			if(!answer){
				top.commonTools.showTip("多选题最少两个答案!", 2);
				return;
			}
		}else if(question_type == "判断题"){
			answer = $("input[name='true_or_false_answer']:checked").val();
		}else if(question_type == "解答题"){
			answer = $("#solution_answer").val();
		}
		
		if(!answer){
			top.commonTools.showTip("请填写或选择答案!", 2);
			return;
		}
		var _answer = answer.replace(/\s+/g,"");
		if(!_answer){
			top.commonTools.showTip("请填写或选择答案!", 2);
			return;
		}
		if(!detailed){
			top.commonTools.showTip("请填写详解", 2);
			return;
		}
		var _detailed = detailed.replace(/\s+/g,"");
		if(!_detailed){
			top.commonTools.showTip("请填写详解", 2);
			return;
		}
		/* if(!course_name){
			top.commonTools.showTip("请选择所属课程", 2);
			return;
		} */
		
		var url = rootPath + "/question/add";
		var map = new Object;
		map.course_name = course_name;
		map.detailed = detailed;
		map.selects = selects;
		map.answer = answer;
		map.class_id = question_type;
		map.question = question;
	    var jsonData = JSON.stringify(map);
		$.ajax({
			url:url,
			method:"post",
			dataType:"json",
			data:{'data':jsonData},
			success:function(data){
				if(data){
					top.commonTools.showTip("新增试题成功!", 1);
					if(parent.status1){
						 parent.status1();
					}
					if(parent.reloadList){
						 parent.reloadList();
					}
				}else{
					top.commonTools.showTip("失败!", 2);
				}
			},
			error:function(){
				top.commonTools.showTip("失败!", 2);
			}
		});
		
	}

	function preview() {
		
	}
	////////将题目答案全部赋空
	function setAnswerEmpty(){
		$("input[name='multiple_choice_answer']").each(function(){
			   $(this).attr("checked",false);
			 });  
		var x=document.getElementsByName("one_choice_answer");  //获取所有name=brand的元素  
	    for(var i=0;i<x.length;i++){ //对所有结果进行遍历，如果状态是被选中的，则将其选择取消  
	        if (x[i].checked==true){  
	            x[i].checked=false;  
	        }  
	    }  
		var y=document.getElementsByName("true_or_false_answer");  //获取所有name=brand的元素  
	    for(var i=0;i<y.length;i++){ //对所有结果进行遍历，如果状态是被选中的，则将其选择取消  
	        if (y[i].checked==true){  
	            y[i].checked=false;  
	        }  
	    }  
	}
	///获取form表单下input框中的值
	function getFormValue(formId) {
		var _form = document.getElementById(formId); //获取该表单下的所有input标签		
		var _inputs = _form.getElementsByTagName("input"); //定义一个收集input标签的name和值 			
		var result = null; //循环这个input数组取值  并将获取name和值拼接成对象赋值给d的对象的第I位		
		for (var i = 0; i < _inputs.length; i++) {
			if (_inputs[i].value != "" && _inputs[i].value != null &&_inputs[i].value.length) {
				var str = _inputs[i].value.replace(/\s+/g,"")
				if(!str){
					return result;
				}
				if (i == 0) {
					result = _inputs[i].value;
				} else {
					result += ",nwebadjj,_" + _inputs[i].value;
				}
			}
		}
		return result;
	}
	//将form中的input全部赋空
	function setFormEmpty(formId) {
		var _form = document.getElementById(formId); //获取该表单下的所有input标签		
		var _inputs = _form.getElementsByTagName("input"); //定义一个收集input标签的name和值 			
		for (var i = 0; i < _inputs.length; i++) {
			_inputs[i].value = null;
		}
	}
	// 获取checkbox选中的值
	function getCheckedValues() {
		var value = "";
		var checkbox = document.getElementsByName('multiple_choice_answer');
		for (var i = 0; i < checkbox.length; i++) {
			if (checkbox[i].checked == true) {
				if (value == "") {
					value = checkbox[i].value;
				} else {
					value += "," + checkbox[i].value;
				}
			}
		}
		if(value.length <2){
			return null;
		}
		return value;
	}
	
	KindEditor.ready(function(K) {
	    var options = {
	        width : '432px',
	        minWidth : "432px",
	        filterMode : true,
	        items : [
		        'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
		        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
		        'justifyfull', '/', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
		        'superscript', 'clearhtml', 'quickformat', '|', 'fullscreen', '/',
		        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
		        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
		        'flash', 'media', '/','insertfile', 'table', 'hr', 'emoticons', 'pagebreak',
		        'anchor', 'link', 'unlink'
				],
			};
		//var editor = K.create('#editor', options);
		/* editor.sync(); */
		$("#save").click(function(){
			save($("#editor").val());
		});
		$("#preview").click(function(){
			$("#dialog").show();
			$(".haha").show();
			$("#question_stem").html($("#stem").val());
			$("#explain_in_detail").html($("#editor").val());
			if(question_type == "单选题"){
				selects = getFormValue("one_choice_form1");//题目选项
				var arr = selects.split(",nwebadjj,_");
				var Htmstr="";
				for(var i = 0; i < arr.length;i++){
					var str = String.fromCharCode(i+65);
					Htmstr += "<li>"
						+"<font>"+str+'、'+arr[i]+"</font>"
					+"</li>";
				}
				$("#select_options").html(Htmstr);
				answer = $("input[name='one_choice_answer']:checked").val();
				$("#preview_answer").html(answer);
			}else if(question_type == "多选题"){
				selects = getFormValue("multiple_choice_form1");//题目选项
				var arr = selects.split(",nwebadjj,_");
				var Htmstr="";
				for(var i = 0; i < arr.length;i++){
					var str = String.fromCharCode(i+65);
					Htmstr += "<li>"
						+"<font>"+str+'、'+arr[i]+"</font>"
					+"</li>";
				}
				$("#select_options").html(Htmstr);
				answer = getCheckedValues();
				$("#preview_answer").html(answer);
			}else if(question_type == "判断题"){
				$("#select_options").html("<li><font>是</font></li><li>&nbsp;"
						+"<font>否</font></li>");
				answer = $("input[name='true_or_false_answer']:checked").val();
				if(answer =="true"){
					$("#preview_answer").html("是");
				}else if(answer =="false"){
					$("#preview_answer").html("否");
				}
			}else if(question_type == "解答题"){
				answer = $("#solution_answer").val();
				$("#select_options").html("<p style =\"height:40px\"></p>");
				$("#preview_answer").html(answer);
			}
			
			/* document.body.style.overflow = "hidden";
			document.documentElement.style.overflow ="hidden"; */
			window.scrollTo(0,0);
		})
	});
	document.getElementsByClassName("haha")[0].style.height = document.documentElement.scrollHeight + "px";
	document.getElementsByClassName("haha")[0].style.width = "100%";
	
	
	function closeBg() {
		$("#dialog").hide();
		$(".haha").hide();
		$("#abc").removeClass("maskLayer");
	}
</script>


</html>